package fundacion;

import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;



public class Apadrinamiento {

	private String orderID;

	private Cliente cliente;

	private TarjetaCredito payment;

	private Date timeplaced;

	private List detalles;

	private String placedbyCustomer;

	public String getOrderID() {
		return orderID;
	}

	public void setOrderID(String orderID) {
		this.orderID = orderID;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public TarjetaCredito getPayment() {
		return payment;
	}

	public void setPayment(TarjetaCredito payment) {
		this.payment = payment;
	}

	public Date getTimeplaced() {
		return timeplaced;
	}

	public void setTimeplaced(Date timeplaced) {
		this.timeplaced = timeplaced;
	}

	public List getDetalles() {
		return detalles;
	}

	public void setDetalles(List detalles) {
		this.detalles = detalles;
	}

	public String getPlacedbyCustomer() {
		return placedbyCustomer;
	}

	public void setPlacedbyCustomer(String placedbyCustomer) {
		this.placedbyCustomer = placedbyCustomer;
	}
	
	public void addDetalle(Detalles detalle){
		boolean found = false;

		if (detalles == null) {
			detalles= new LinkedList();
		}
		else{

			for (Iterator iter = detalles.iterator(); iter.hasNext();) {
				Detalles d = (Detalles) iter.next();
				if (d.getNino().getId().equals(
						detalle.getNino().getId())) {
					d.setDinero(d.getDinero() + detalle.getDinero());
					found = true;
				}
			}
		}
		if (!found) {
			detalles.add(detalle);
		}			
	}

	public void removeDetail(String pid) {
		boolean found = false;
		Iterator iter = detalles.iterator();
		while (iter.hasNext() && !found) {
			Detalles d = (Detalles) iter.next();
			if (d.getNino().getId().equals(pid)) {
				detalles.remove(d);
				found = true;
			}
		}
	}

}
